/* 阿里云滑动验证控件
  * 文档: https://help.aliyun.com/document_detail/66317.html?spm=5176.2020520162.0.0.64e35fb0QnZHCW
  * js资源已经在index.html模板中通过<script>引入
  * */
const initNCValidator = function(callback) {
  if (!(typeof window.noCaptcha === 'function')) {
    return;
  }
  const appkey = 'FFFF0N5N0000000069E7';
  const scene = 'nc_login';
  const nc_token = [appkey, (new Date()).getTime(), Math.random()].join(':');
  const NC_Opt = {
    renderTo: '#nc-container',
    appkey, // appkey和scene配置在阿里云控制台, 如有疑问联系测试团队   
    scene,
    token: nc_token,
    customWidth: '100%',
    trans: { 'key1': 'code0' },
    elementID: ['username'],
    is_Opt: 0,
    language: 'cn',
    isEnabled: true,
    timeout: 3000,
    times: 5,
    apimap: {
      // 'analyze': '//a.com/nocaptcha/analyze.jsonp',
      // 'get_captcha': '//b.com/get_captcha/ver3',
      // 'get_captcha': '//pin3.aliyun.com/get_captcha/ver3'
      // 'get_img': '//c.com/get_img',
      // 'checkcode': '//d.com/captcha/checkcode.jsonp',
      // 'umid_Url': '//e.com/security/umscript/3.2.1/um.js',
      // 'uab_Url': '//aeu.alicdn.com/js/uac/909.js',
      // 'umid_serUrl': 'https://g.com/service/um.json'
    },
    // 前端滑动验证通过时会触发此回调
    callback: function(data) {
      console.log(data)
      callback({
        token: nc_token,
        sessionId: data.csessionid,
        sig: data.sig,
        scene
      });
    }
  };
  const nc = new window.noCaptcha(NC_Opt);
  nc.upLang('cn', {
    _startTEXT: '请按住滑块，拖动到最右边',
    _yesTEXT: '验证通过',
    _error300: '哎呀，出错了，点击<a href="javascript:__nc.reset()">刷新</a>再来一次',
    _errorNetwork: '网络不给力，请<a href="javascript:__nc.reset()">点击刷新</a>'
  })
  return nc;
};

export default initNCValidator
